#!/usr/bin/python

from socket import *
import getopt, sys

def printHelp():
    """Print out instructions on using this script"""
    print ""
    print "Usage: client -s HOST -p PORT"
    print ""

HOST = 'localhost'
PORT = 21567

 #Get params from Command Line
try:
    opts, args = getopt.getopt(sys.argv[1:], "hs:p:", ["help", "server=", "port="])
except getopt.GetoptError, err:
        print str(err)
        sys.exit(2)
        printHelp()
               
for o,p in opts:
    if o in ['-h','--help']:
        printHelp()
        sys.exit(0)
    elif o in ['-s','server']:
        HOST = p
    elif o in ['-p', 'port']:
        PORT = 1
    else:
        printHelp()
        sys.exit(2)
        
ADDR = (HOST, PORT)
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)

while 1:
    data = raw_input('> ')
    if not data: break 
    if data == 'close': break
    tcpCliSock.send(data)
    
    #Don't expect anything back for the time being
    #data = tcpCliSock.recv(1024)
    #if not data: break 
    #print data

tcpCliSock.close()
